export default {
	/**
	 * 异步存储
	 */
	setStorage: (key, data) => {
		return new Promise((resolve, reject) => {
			uni.setStorage({
				key: key,
				data: data,
				success: function() {
					resolve('success');
				},
				fail: function() {
					reject(`异步存储${key}失败`)
				}
			})
		})
	},
	/**
	 * 异步读取
	 */
	getStorage: (key) => {
		return new Promise((resolve, reject) => {
			uni.getStorage({
				key: key,
				success: function(res) {
					resolve(res.data);
				},
				fail: function(err) {
					reject(`异步读取${key}失败`)
				}
			});
		})
	},
	/**
	 * 同步存储
	 */
	setStorageSync: (key, data) => {
		try {
			uni.setStorageSync(key, data);
		} catch (e) {
			console.error(`同步存储${key}失败`)
		}
	},
	/**
	 * 同步读取
	 */
	getStorageSync: (key) => {
		try {
			return uni.getStorageSync(key);
		} catch (e) {
			console.error(`同步读取${key}失败`)
		}
	},
	/**
	 * 获取存储信息
	 */
	getStorageInfo: () => {
		return new Promise((resolve, reject) => {
			uni.getStorageInfo({
				success: function(res) {
					resolve(res)
				},
				fail: function() {
					reject('调用getStorageInfo接口失败')
				}
			});
		})
	},
	/**
	 * 异步删除存储数据
	 */
	removeStorage: (key) => {
		return new Promise((resolve, reject) => {
			uni.removeStorage({
				key: key,
				success: function(res) {
					resolve(res.data);
				},
				fail: function(err) {
					reject(`异步删除${key}失败`)
				}
			})
		})
	},
	/**
	 * 同步删除存储数据
	 */
	removeStorageSync:(key)=>{
		try {
		    uni.removeStorageSync('storage_key');
		} catch (e) {
		    console.error(`同步删除${key}失败`)
		}
	},
	/**
	 * 同步清理本地数据缓存
	 */
	clearStorage:()=>{
		uni.clearStorageSync()
	}
}
